package com.sos.data.adapters
{
	import com.sos.core.game.GameOptions;

	public class GameOptionsAdapter
	{
		public static function fromXML(xml:XML):GameOptions
		{
			// Create new configurtion
			var options:GameOptions = new GameOptions();
			// Safe exec
			try
			{
				// Properties
				options.turns 						= uint(xml.turns);
				options.deckSize 					= uint(xml.deckSize);
				options.handSize 					= uint(xml.handSize);
				options.discardSize 				= uint(xml.discardSize);
				options.timeoutEnabled 				= Boolean(xml.timeouts.@enabled == "1");
				options.timeoutPlayPhase 			= uint(xml.timeouts.play);
				options.timeoutDiscardPhase 		= uint(xml.timeouts.discard);
				options.timeoutSubstitutionPhase 	= uint(xml.timeouts.substitution);
			}
			// Unexpected exception
			catch (e:Error)
			{
				throw new Error("GameOptionsAdapter.fromXML() unexpected error: " + e.toString());
			}
			return options;
		}
	}
}